package gameAppLayer.gui;

import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.EffectBuilder;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.builder.TextBuilder;
import de.lessvoid.nifty.controls.Controller;
import de.lessvoid.nifty.controls.button.ButtonControl;
import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;
import de.lessvoid.nifty.controls.checkbox.builder.CheckboxBuilder;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.elements.render.ImageRenderer;
import de.lessvoid.nifty.loaderv2.NiftyLoader;
import de.lessvoid.nifty.loaderv2.types.NiftyType;
import de.lessvoid.nifty.render.NiftyImage;
import de.lessvoid.nifty.screen.Screen;
import effects.MoveEffectBuilder;

/*
 * A factory that creates the MainMenu GUIState
 */
public class FGUIMainMenu {
	
	
	
	public Screen createScreen(Nifty nifty) {
		
				
		Screen mainScreen = new ScreenBuilder(EGUIStates.MAIN_MENU.toString()) {{
			controller(new CGUIMainMenu());

			//inputMapping("de.lessvoid.nifty.input.mapping.DefaultScreenMapping");

			layer(new LayerBuilder("backgroundLayer") {{				
				backgroundImage("assets/Interface/Backgrounds/HubbleGalaxy3.png");				
			}});
			
			layer(new LayerBuilder("contentLayer") {{
				backgroundColor("#fff0");
				childLayoutVertical();


				/*panel(new PanelBuilder("top") {{
					backgroundColor("#f006");
					height(pixels(100));					
				}});*/

				panel(new PanelBuilder("middle") {{
					backgroundColor("#0005");
					//backgroundColor("#0f06");
					childLayoutCenter();
					width(percentage(20));
					//height(percentage(40));
					alignCenter();
					valignCenter();
					height("*");
					visibleToMouse();
					padding(pixels(10));

					onStartScreenEffect(new MoveEffectBuilder() {{
						mode(inMode());
						direction(leftDirection());
						length(500);
						startDelay(0);
						inherit(true);
					}});

					onEndScreenEffect(new MoveEffectBuilder() {{
						mode(outMode());
						direction(rightDirection());
						length(500);
						startDelay(0);
						inherit(true);						
					}});

					panel(new PanelBuilder("menu-main") {{
						childLayoutVertical();
						alignCenter();
						valignCenter();
						width(percentage(100));
						
						control(new ButtonBuilder("newGameButton", "New Game") {{ //play
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("newGame()");							
						}});
						
						control(new ButtonBuilder("loadGameButton", "Load") {{ //play
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("loadGame()");							
						}});
						
						control(new ButtonBuilder("optionsButton", "Options") {{
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("options()");							
						}});
						
						control(new ButtonBuilder("tutorialButton", "Tutorials") {{ //play
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("tutorials()");							
						}});
						
						control(new ButtonBuilder("modsButton", "Mods") {{ //play
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("mods()");							
						}});
						
						control(new ButtonBuilder("aboutButton", "About") {{ //play
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("about()");							
						}});
						
						control(new ButtonBuilder("exitGameButton", "Exit Game") {{ //play
							width(pixels(100));
							alignCenter();
							valignCenter();

							interactOnClick("exitGame()");							
						}});
						
						/*text(new TextBuilder() {{
							text("Test");
							font("aurulent-sans-16.fnt");
							color("#000f");
							width("*");
							alignCenter();
							valignCenter();
							
							padding(pixels(50));
						}});	*/					
					}});
				}});

				/*panel (new PanelBuilder("bottom") {{
					backgroundColor("#00f6");
					height(pixels(100));
				}});*/

			}});
			//}});
		}}.build(nifty);
		
		//NiftyImage newImage = nifty.getRenderEngine().createImage("assets/Interface/Backgrounds/HubbleGalaxy2.png", false);
		//Element element = mainScreen.findElementByName("layer");
		//element.getRenderer(ImageRenderer.class).setImage(newImage);
		
		
		return mainScreen;
	
	}
	
	
	
}
